package com.jinbei.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jinbei.domain.Role;
import com.jinbei.mapper.RoleMapper;
import com.jinbei.service.RoleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author zflu
 * Created by lucky on 2018/7/9.
 */
@Service
public class RoleServiveImpl implements RoleService{

    private final Logger logger = LoggerFactory.getLogger(RoleServiveImpl.class);

    @Autowired
    private RoleMapper roleMapper;

    /**
     * @author zflu
     * @Description  角色新增
     * @date 2018/7/9 15:14
     * @param role
     * @return int
     */
    @Transactional(rollbackFor = {Exception.class})
    @Override
    public int insertRole(Role role) throws Exception {
        return  roleMapper.insertRole(role);
    }

    /**
     * @author zflu
     * @Description  角色修改
     * @date 2018/7/9 15:15
     * @param role
     * @return int
     */
    @Transactional(rollbackFor = {Exception.class})
    @Override
    public int updateRole(Role role) throws Exception {
        return roleMapper.updateRole(role);
    }

    /**
     * @author zflu
     * @Description 根据角色id删除角色
     * @date 2018/7/9 15:16
     * @param roleId
     * @return int
     */
    @Transactional(rollbackFor = {Exception.class})
    @Override
    public int deleteRoleByRoleId(int roleId) throws Exception {
        return roleMapper.deleteRoleByRoleId(roleId);
    }

    /**
     * @author zflu
     * @Description 根据角色id查询角色
     * @date 2018/7/9 15:18
     * @param roleId
     * @return com.jinbei.domain.Role
     */
    @Override
    public Role queryRoleByRoleId(int roleId) throws Exception {
        return roleMapper.queryRoleByRoleId(roleId);
    }

    /**
     * @author zflu
     * @Description  角色分页列表
     * @date 2018/7/12 9:17
     * @param pageNum, pageSize
     * @return com.github.pagehelper.PageInfo
     */
    @Override
    public PageInfo queryRolePage(int pageNum, int pageSize) throws Exception {
        PageHelper.startPage(pageNum,pageSize);
        List<Role> roles = roleMapper.queryRolePage();
        return new PageInfo(roles);
    }
}
